using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for SqlServerObjectProvider
/// </summary>
public partial class DataProvider
{     
    
    #region GetItemArray
    public object[] GetItemArray()
    {
        object[] obj = null;
        DataTable dataTable = new DataTable();
        sqlCommand = new SqlCommand();
        sqlCommand.CommandText = commandText;
        sqlCommand.Connection = sqlConnection;
        sqlCommand.CommandType = commandType;
        if (ParameterCollection != null)
            AddParameters();
        SqlDataAdapter sqlDataAdapter = 
        new SqlDataAdapter(sqlCommand);
        sqlDataAdapter.Fill(dataTable); 
        if (dataTable.Rows.Count > 0)
            obj = dataTable.Rows[0].ItemArray;
        sqlCommand.Dispose();
        sqlDataAdapter.Dispose();
        return obj;
    }
    #endregion

    #region GetObject
    public object[] GetObject( )
    {
        object[] obj = null;
        sqlCommand = new SqlCommand();
        sqlCommand.CommandText = commandText;
        sqlCommand.Connection = sqlConnection;
        sqlCommand.CommandType = commandType;

        if (ParameterCollection != null)
            AddParameters();

        SqlDataReader sqlDataReader = 
        sqlCommand.ExecuteReader();

        if (sqlDataReader.Read())
        {
            obj = new object[sqlDataReader.FieldCount];
            sqlDataReader.GetValues(obj);
        }
        sqlDataReader.Close();
        sqlDataReader.Dispose();
        sqlCommand.Dispose();
        return obj;
    }
    #endregion

    #region GetStrings
    public string[] GetStrings( )
    {
        string[] str = null;
        sqlCommand = new SqlCommand();
        sqlCommand.CommandText = commandText;
        sqlCommand.Connection = sqlConnection;
        sqlCommand.CommandType = commandType;

        if (ParameterCollection != null)
            AddParameters();
        SqlDataReader sqlDataReader = 
        sqlCommand.ExecuteReader();
        str = new string[sqlDataReader.FieldCount];
        if (sqlDataReader.Read())
        {
            for (int i = 0; i < sqlDataReader.FieldCount; i++)
            {
                str[i] = Convert.ToString(sqlDataReader[i]);
            }
        }
        sqlDataReader.Close();
        sqlDataReader.Dispose();
        sqlCommand.Dispose();
        return str;
    }

    #endregion

    #region GetArrayList
    public ArrayList GetArrayList()
    {
        ArrayList arrayList = new ArrayList();
        string[] stringValue = null;
        sqlCommand = new SqlCommand();
        sqlCommand.CommandText = commandText;
        sqlCommand.Connection = sqlConnection;
        sqlCommand.CommandType = commandType;
        if (ParameterCollection != null)
            AddParameters();
        SqlDataReader  sqlDataReader = 
        sqlCommand.ExecuteReader();
        int cols = sqlDataReader.FieldCount;

        while (sqlDataReader.Read())
        {
            stringValue = new string[cols];
            for (int i = 0; i < cols; i++)
            {
                stringValue[i] = Convert.ToString(sqlDataReader[i]);
            }
            arrayList.Add(stringValue);
        }
        sqlDataReader.Close();
        sqlDataReader.Dispose();
        sqlCommand.Dispose();
        return arrayList;
    }
    #endregion
    
}
